package com.hskn.hss.module.gridbind.controller;


import com.hskn.hss.core.annotation.SysLog;
import com.hskn.hss.core.enums.BusinessType;
import com.hskn.hss.entity.AjaxResult;
import com.hskn.hss.module.cases.mapper.CasesMapper;
import com.hskn.hss.module.gridbind.To.GridBindByAppVo;
import com.hskn.hss.module.gridbind.To.GridBindTo;
import com.hskn.hss.module.gridbind.entity.GridBind;
import com.hskn.hss.module.gridbind.mapper.GridBindMapper;
import com.hskn.hss.module.gridbind.service.IGridBindService;
import com.hskn.hss.module.gridbind.vo.GridBindPunchCardVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author hskn
 * @since 2021-05-25
 */
@Api(tags = {"-gridbind"}, description = "绑定对象")
@Slf4j
@RestController
@RequestMapping("/hss/gridBind")
public class GridBindController {
    @Autowired
    private IGridBindService iGridBindService;

//    @SysLog(businessType = BusinessType.DELETE, tableName = "grid_bind", idKey = "id", bean = GridBind.class, beanMapper = GridBindMapper.class, names = "gridName")
    @ApiOperation(value = "电子围栏解绑对象接口", notes = "电子围栏解绑对象")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = GridBind.class)
    })
    @RequestMapping(value = "delete", method = RequestMethod.POST)
    public AjaxResult<Object> delete(@RequestBody @Validated GridBindTo gridBindTo) {
        try {
            iGridBindService.delete(gridBindTo);
            return AjaxResult.success("解绑成功");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @ApiOperation(value = "【APP】用户端-打卡/查询签到基础信息接口", notes = "【APP】用户端-打卡")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = GridBindPunchCardVo.class)
    })
    @RequestMapping(value = "getGridBindList", method = RequestMethod.POST)
    public AjaxResult<Object> getGridBindList(@RequestBody @Validated GridBindTo gridBindTo) {
        try {

            return AjaxResult.success(iGridBindService.getGridBindList(gridBindTo));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

    @ApiOperation(value = " 【APP】用户端-打卡 / 查询当前位置是否在电子围栏中", notes = " 【APP】用户端-打卡 / 查询当前位置是否在电子围栏中")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = GridBindPunchCardVo.class)
    })
    @RequestMapping(value = "getIsInGrid", method = RequestMethod.POST)
    public AjaxResult<Object> getIsInGrid(@RequestBody @Validated GridBindByAppVo gridBindByAppVo) {
        try {

            return AjaxResult.success(iGridBindService.getIsInGrid(gridBindByAppVo));
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

//    @SysLog()
    @ApiOperation(value = "【APP】用户端-打卡 / 电子围栏签到", notes = "【APP】用户端-打卡 / 电子围栏签到")
    @ApiResponses({
            @ApiResponse(code = 200, message = "ok", response = GridBindPunchCardVo.class)
    })
    @RequestMapping(value = "punchCard", method = RequestMethod.POST)
    public AjaxResult<Object> punchCard(@RequestBody @Validated GridBindByAppVo gridBindByAppVo) {
        try {
            iGridBindService.punchCard(gridBindByAppVo);
            return AjaxResult.success("操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            log.error("报错ERROR", e);
            return AjaxResult.fail("操作失败");
        }
    }

}

